﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Velocity4Net.Ctx;

namespace Velocity4Net.App.Events
{
    /**
       * Defines the execution strategy for referenceInsert
       * @since 1.5
       */
    public class referenceInsertExecutor : EventHandlerMethodExecutor
    {
        private IContext context;
        private String reference;
        private Object value;

        public referenceInsertExecutor(
                IContext context,
                String reference,
                Object value)
        {
            this.context = context;
            this.reference = reference;
            this.value = value;
        }

        /**
         * Call the method referenceInsert()
         *  
         * @param handler call the appropriate method on this handler
         */
        public void execute(EventHandler handler)
        {
            ReferenceInsertionEventHandler eh = (ReferenceInsertionEventHandler)handler;

            //if (eh is ContextAware)
            //    ((ContextAware) eh).setContext(context);

            /**
             * Every successive call will alter the same value
             */
            value = ((ReferenceInsertionEventHandler)handler).referenceInsert(reference, value);
        }

        public Object getReturnValue()
        {
            return value;
        }

        /**
         * Continue to end of event handler iteration
         * 
         * @return always returns false
         */
        public bool isDone()
        {
            return false;
        }
    }
}
